<?php
 /*引入核心数据库操作类*/
ob_start();
header("Content-Type: text/html; charset=utf-8");
define('ROOT_PATH', str_replace('Manager/action.php', '', str_replace('\\', '/', __FILE__)));
if($_GET[api]) {
	define('IN_ECS', true);
	require_once ROOT_PATH."Common/init.php";
}else { 
	require_once (ROOT_PATH . 'Lib/Db/DB.class.php');
}
require_once (ROOT_PATH . 'Manager/Page.class.php');
//function object_to_array($obj)
//{
//$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
//foreach ($_arr as $key => $val)
//{
//$val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val;
//$arr[$key] = $val;
//}
//return $arr;
//}
if($_GET[action]) {
	$className =  strtoupper(substr($_GET[action],0,1)).substr($_GET[action],1);
	$page = new Page();
	try{ 
		require (ROOT_PATH . 'Manager/action/'.$className.'.class.php');
		$action = new $className;
	} catch(Exception $e) {
			$page->success = false;
			$page->info = "不存在类::".$className;
	}
	if($page->success && $_GET[method]) {
		try{ 
			$method = $_GET[method];
			$action->$method();
		} catch(Exception $e) {
			$page->success = false;
			$page->info = "不存方法{$className}::".$_GET[method];
		}
	} else {
		try{ 
			$action->execute() ;
		} catch(Exception $e) {
			$page->success = false;
			$page->info = "不存方法{$className}::execute";
		}
	}
	$page->success = true;
	$oth = ob_get_contents() ;
	$page->info .= $oth;
	ob_end_clean();
	ob_end_flush();
	echo json_encode(($page));
	
}

?>
